package com.ctsi.flowable.engine.config;

import org.flowable.common.engine.impl.cfg.IdGenerator;
import org.flowable.job.service.impl.asyncexecutor.AsyncExecutor;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.FlowableMailProperties;
import org.flowable.spring.boot.FlowableProperties;
import org.flowable.spring.boot.ProcessEngineAutoConfiguration;
import org.flowable.spring.boot.app.FlowableAppProperties;
import org.flowable.spring.boot.idm.FlowableIdmProperties;
import org.flowable.spring.boot.process.FlowableProcessProperties;
import org.flowable.spring.boot.process.Process;
import org.flowable.spring.boot.process.ProcessAsync;
import org.flowable.spring.boot.process.ProcessAsyncHistory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
import java.io.IOException;

/**
 * @Auther: zhangjw
 * @Date: 2018/8/24 02:10
 * @Description:
 */
@Configuration
public class FlowableEngineConfig extends ProcessEngineAutoConfiguration {

    public FlowableEngineConfig(FlowableProperties flowableProperties,
                                FlowableProcessProperties processProperties,
                                FlowableAppProperties appProperties,
                                FlowableIdmProperties idmProperties,
                                FlowableMailProperties mailProperties) {
        super(flowableProperties, processProperties, appProperties, idmProperties, mailProperties);
    }

    @Override
    public SpringProcessEngineConfiguration springProcessEngineConfiguration(DataSource dataSource, PlatformTransactionManager platformTransactionManager,
                                                                             @Process ObjectProvider<IdGenerator> processIdGenerator,
                                                                             ObjectProvider<IdGenerator> globalIdGenerator,
                                                                             @ProcessAsync ObjectProvider<AsyncExecutor> asyncExecutorProvider,
                                                                             @ProcessAsyncHistory ObjectProvider<AsyncExecutor> asyncHistoryExecutorProvider) throws IOException {
        SpringProcessEngineConfiguration conf =  super.springProcessEngineConfiguration(dataSource, platformTransactionManager,processIdGenerator,
                globalIdGenerator, asyncExecutorProvider, asyncHistoryExecutorProvider);
//        String databaseSchema = conf.getDatabaseSchema();
//        conf.setDatabaseCatalog(databaseSchema);
//        conf.setDatabaseTablePrefix(databaseSchema + ".");
//        conf.setTablePrefixIsSchema(true);
        conf.setActivityFontName("黑体");
        conf.setLabelFontName("黑体");
        conf.setAnnotationFontName("黑体");
        return conf;
    }
}
